package com.felix.algorithms.planning;

import static com.google.common.primitives.Ints.max;

/**
 * HouseRobber
 *
 * @author xuejinhua
 * @date 2018/9/13 13:59
 */
public class HouseRobber {

    /**
     * Q198
     *
     * @return
     */
    public static int solution(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        if (nums.length == 1) {
            return nums[0];
        }
        int[] values = new int[2];
        values[0] = nums[0];
        values[1] = max(nums[0], nums[1]);
        for (int i = 2; i < nums.length; i++) {
            int temp = values[1];
            values[1] = Math.max(values[0] + nums[i], values[1]);
            values[0] = temp;
        }
        return values[1];
    }

    public static void main(String[] args) {
        int[] nums = {2, 1, 1, 2};
        System.out.println(solution(nums));
    }
}
